app.register.controller("IndexCtrl", ["$rootScope", "$scope", "$location", "$timeout", "$window", "ToastMessage", "SecurityService", "FundService", "StockService", "UserService", "$q", function($rootScope, $scope, $location, $timeout, $window, ToastMessage, SecurityService, FundService, StockService, UserService, $q) {
    function autoRefresh() {
        return isIn ? void (timer = setTimeout(function() {
            $scope.loadData()["finally"](autoRefresh)
        }, interval)) : !1
    }
    app.util.setTitle(""),
    $timeout(function() {
        $rootScope.appLoaded = !0
    }, 50);
    var swiper2, isIn = !0;
    new Swiper(".swiper-container",{
        pagination: ".I_pagination",
        grabCursor: !0,
        autoplay: 3e3,
        speed: 700,
        autoplayDisableOnInteraction: !1,
        loop: !0,
        paginationClickable: !0,
        onInit: function(swiper) {
            1 === swiper.slides.length && (swiper.paginationContainer[0].style.opacity = 0)
        }
    });
    $scope.hangQing = function(p) {
        return p ? void ("CHINA_HK" == p.market ? $location.url("/hkstk/timeshare?market=" + p.market + "&code=" + p.code) : "CHINA_SH" == p.market || "CHINA_SZ" == p.market ? $location.url("/cnstk/timeshare?market=" + p.market + "&code=" + p.code) : ("US_NYSE" == p.market || "US_AMEX" == p.market || "US_NASDAQ" == p.market) && $location.url("/usstk/timeshare?market=" + p.market + "&code=" + p.code)) : !1
    }
    ,
    $scope.bullBear = function(p) {
        return p && p.serial ? void $location.url("/bullbear/levertrade?serial=" + p.serial) : !1
    }
    ,
    $scope.bullBearHistoryList = function() {
        $location.url("/bullbear/leverincome")
    }
    ,
    $scope.bullBearRule = function() {
        $location.url("/bullbear/leverrule")
    }
    ,
    $scope.getZf = function(p) {
        if (!p)
            return "-";
        var inc = p.orginIncPercent;
        return 0 != inc && inc ? inc > 0 ? "+" + inc.toFixed(2) + "%" : inc.toFixed(2) + "%" : "0.00%"
    }
    ;
    var funs = {
        pageLoad: function() {
            return $q.all([funs.getBullBear(), funs.getProcessingCount()])
        },
        getBullBear: function() {
            var bullBearPromise = StockService.bullBearList();
            return bullBearPromise.success(function(data) {
                if (data && data.success)
                    if (data.result.itemList && ($scope.bullBearList = data.result.itemList.list),
                    void 0 != $scope.bullBearList && $scope.bullBearList.length >= 1)
                        $("#bullBearDiv").removeClass("none"),
                        $("#titleIndex").html($scope.bullBearList[0].titleIndex),
                        $timeout(function() {
                            (void 0 == swiper2 || void 0 == $scope.bullBearCount || $scope.bullBearCount != $scope.bullBearList.length) && ($scope.bullBearCount = $scope.bullBearList.length,
                            swiper2 = new Swiper(".I_lever_list",{
                                pagination: ".lever_pagination",
                                grabCursor: !0,
                                autoplay: !1,
                                speed: 400,
                                autoplayDisableOnInteraction: !1,
                                loop: !1,
                                paginationClickable: !0,
                                onInit: function(swiper) {
                                    swiper.slides.length <= 1 ? swiper.paginationContainer[0].style.opacity = 0 : swiper.paginationContainer[0].style.opacity = 1
                                },
                                onSlideChangeEnd: function(swiper) {
                                    $scope.activeIndex = swiper.activeIndex,
                                    $("#titleIndex").html($scope.bullBearList[$scope.activeIndex].titleIndex)
                                }
                            }))
                        }, 100),
                        $scope.activeIndex = 0;
                    else {
                        var memberId = data.result.memberId
                          , uInfoPromise = UserService.getUserBasicInfo(memberId);
                        uInfoPromise.success(function(data) {
                            data.result && data.result[0] && data.result[0].headImg && ($scope.headImg = $rootScope.formatImgUrl(data.result[0].headImg))
                        }),
                        $scope.userCount = data.result.userCount,
                        $scope.userName = data.result.userName,
                        $scope.userAmount = data.result.amount,
                        $("#titleIndex").html(""),
                        $timeout(function() {
                            swiper2 = new Swiper(".I_lever_list",{
                                pagination: ".lever_pagination",
                                grabCursor: !0,
                                autoplay: !1,
                                speed: 400,
                                autoplayDisableOnInteraction: !1,
                                loop: !1,
                                paginationClickable: !0,
                                onInit: function(swiper) {
                                    swiper.slides.length <= 1 && (swiper.paginationContainer[0].style.opacity = 0)
                                },
                                onSlideChangeEnd: function(swiper) {
                                    $scope.activeIndex = swiper.activeIndex
                                }
                            })
                        }, 100),
                        $("#bullBearDiv").addClass("none")
                    }
            }),
            bullBearPromise
        },
        getProcessingCount: function() {
            var processCountPromise = StockService.bullBearProcessing();
            return processCountPromise.success(function(data) {
                data && data.success && data.result && (void 0 == data.result.count || data.result.count <= 0 ? $("#myCount").hide() : $scope.myCount = data.result.count)
            }),
            processCountPromise
        }
    };
    $scope.loadData = funs.pageLoad;
    var timer = null 
      , interval = 3e4;
    $scope.loadData(),
    autoRefresh(),
    $scope.$on("$destroy", function() {
        isIn = !1,
        clearTimeout(timer),
        $("#openUrlifr").remove()
    })
}
]);
